package com.strato.mvc.i18n.v1_0_0.resolvers;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.strato.mvc.i18n.v1_0_0.LocaleResolver;

public class SessionResolver implements LocaleResolver {

	public static final String DEFAULT_SESSION_ATTRIBUTE_NAME="_LOCALE_";
	
	private static SessionResolver instance=new SessionResolver();
	
	public static SessionResolver getInstance() {
		return instance;
	}

	@Override
	public Locale load(HttpServletRequest request, HttpServletResponse response) {
		return (Locale) request.getSession().getAttribute(DEFAULT_SESSION_ATTRIBUTE_NAME);
	}

	@Override
	public void save(Locale locale, HttpServletRequest request, HttpServletResponse response) {
		request.getSession().setAttribute(DEFAULT_SESSION_ATTRIBUTE_NAME, locale);
	}

}
